﻿package plugin.instances
{
    import com.core.*;
    import com.sh.game.util.*;
    import manager.*;
    import plugin.instance.*;
    import plugin.newvip.model.*;
    import view.message.*;
    import view.uilt.*;

    public class InstancesControl extends Control
    {

        public function InstancesControl(param1:Object)
        {
            super(param1);
            return;
        }// end function

        override public function update(param1:Obproxy, param2:ProxyChange) : void
        {
            var useBind:Boolean;
            var mapid:int;
            var user:Object;
            var curmapid:int;
            var instancecfg:Object;
            var cfg:Object;
            var cs:Array;
            var dayinstances:Object;
            var hascount:int;
            var canbuy:int;
            var instancereset:Object;
            var cost:int;
            var viplv:int;
            var o:* = param1;
            var arg:* = param2;
            if (o.getName() == "mainuiInstance")
            {
                if (arg.property == "init")
                {
                    this.target.updateShow(InstancesPublic.GROUPNORMALCOPY, InstancesPublic.TIMECHECKER, arg.newvalue);
                }
                else if (arg.property == "addexp")
                {
                    this.target.updateShow(InstancesPublic.GROUPNORMALCOPY, InstancesPublic.ADDEXP, arg.newvalue);
                }
                else if (arg.property == "MonsterNumber")
                {
                    this.target.updateShow(InstancesPublic.GROUPNORMALCOPY, InstancesPublic.MONSTERNUM, arg.newvalue);
                }
                else if (arg.property == "shiwangdianInfo")
                {
                    this.target.updateShow(InstancesPublic.GROUPNORMALCOPY, InstancesPublic.INITSHIWANGDIAN, arg.newvalue);
                }
                else if (arg.property == "heshangdatingInfo")
                {
                    this.target.updateShow(InstancesPublic.GROUPNORMALCOPY, InstancesPublic.HESHANGTATINGINFO, arg.newvalue);
                }
                else if (arg.property == "swdchishizhe")
                {
                    this.target.updateShow(InstancesPublic.GROUPNORMALCOPY, InstancesPublic.SHIWANGDIANCHIYOUZHE, arg.newvalue);
                }
                else if (arg.property == "updateStatus")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.UPDATESTATUS, arg.newvalue);
                }
                else if (arg.property == "nextWave")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.NEXTWAVE, arg.newvalue);
                }
                else if (arg.property == "superTfInit")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.INITSUPERTF, arg.newvalue);
                }
                else if (arg.property == "createSuperTF")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.CREATESUPERTF, arg.newvalue);
                }
                else if (arg.property == "tdInfo")
                {
                    this.target.updateShow(InstancesPublic.GROUPTD, InstancesPublic.INITSUPERTF, arg.newvalue);
                }
                else if (arg.property == "moneytreeinfo")
                {
                    this.target.updateShow(InstancesPublic.GROUPYAOQIANSHU, InstancesPublic.INITYAOQIANSHU, arg.newvalue);
                }
                else if (arg.property == "yqsliquan")
                {
                    this.target.updateShow(InstancesPublic.GROUPYAOQIANSHU, InstancesPublic.YAOQIANSHULIQUAN, arg.newvalue);
                }
                else if (arg.property == "fuckPoint")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.FUCKPOINT, arg.newvalue);
                }
                else if (arg.property == "swyMsg")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.SWYMSG, arg.newvalue);
                }
                else if (arg.property == "swyBossKill")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.SWYBOSSKILL, null);
                }
                else if (arg.property == "updateBag")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.UPDATEBAG, null);
                }
                else if (arg.property == "ywzlInit")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YWZLINIT, arg.newvalue);
                }
                else if (arg.property == "ywzlBossKill")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YWZLBOSSKILL, arg.newvalue);
                }
                else if (arg.property == "ywzlScoreChange")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YWZLSCORECHANGE, arg.newvalue);
                }
                else if (arg.property == "yxfmgInit")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YXFMGINIT, arg.newvalue);
                }
                else if (arg.property == "yxfmgWave")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YXFMGWAVE, arg.newvalue);
                }
                else if (arg.property == "yxfmgChange")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YXFMGCHANGE, arg.newvalue);
                }
                else if (arg.property == "yhfgkill")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YHFGSOMEONEBEKILLED, arg.newvalue);
                }
                else if (arg.property == "yhfgcamp")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YHFGSELFCAMP, arg.newvalue);
                }
                else if (arg.property == "yhfgscore")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YHFGSELFSCORE, arg.newvalue);
                }
                else if (arg.property == "yhfgrank")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YHFGRANK, arg.newvalue);
                }
                else if (arg.property == "smmzroom")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.SMMZROOM, arg.newvalue);
                }
                else if (arg.property == "sbkarea")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.SBKAREA, arg.newvalue);
                }
                else if (arg.property == "clearance")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.CLEARANCE, arg.newvalue);
                }
                else if (arg.property == "isGet")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.ISGET, arg.newvalue);
                }
                else if (arg.property == "unionBossReward")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.UNIONBOSSREWARD, arg.newvalue);
                }
                else if (arg.property == "unionCollection")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.UNIONCOLLECTION, arg.newvalue);
                }
                else if (arg.property == "unionCollectionRank")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.UNIONCOLLECTIONRANK, arg.newvalue);
                }
                else if (arg.property == "yhfgSelfRankChange")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YHFGRANKCHANGE, arg.newvalue);
                }
                else if (arg.property == "yxfmgNextWaveTime")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YXFMGNEXTWAVETIME, arg.newvalue);
                }
                else if (arg.property == "yxfmgBossState")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.YXFMGBOSSSTATE, arg.newvalue);
                }
                else if (arg.property == "emsFuckingState")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.EMSFUCKINGSTATE, arg.newvalue);
                }
                else if (arg.property == "emsFinished")
                {
                    this.target.updateShow(InstancesPublic.GROUPNONE, InstancesPublic.EMSFINISHED, arg.newvalue);
                }
                else if (arg.property == "enterInstance")
                {
                    useBind;
                    mapid = int(arg.newvalue);
                    user = UserData.getUserData();
                    curmapid = user.mapid;
                    if (curmapid > 10000)
                    {
                        ModelProxy.change("movetips", "error", "已经在副本中");
                        return;
                    }
                    instancecfg = ConfigDictionary.data.instance;
                    cfg = instancecfg[mapid];
                    if (!ItemUilt.checkUserLevelRein(cfg.open_level, cfg.rein))
                    {
                        ModelProxy.change("movetips", "error", "您的等级不足，不能挑战该副本哦！");
                        return;
                    }
                    cs = (cfg.limit_times as String).split(" ");
                    if (cs[1])
                    {
                        dayinstances = ModelProxy.getValue("data", "dayinstances");
                        if (dayinstances && dayinstances[mapid])
                        {
                            hascount = dayinstances[mapid];
                            if (hascount >= cs[1])
                            {
                                canbuy;
                                if (cfg.canbuy != null)
                                {
                                    viplv = VipCheck.checkVipLevel();
                                    if (viplv > 0)
                                    {
                                        canbuy = cfg.canbuy[viplv];
                                    }
                                    else
                                    {
                                        canbuy = cfg.canbuy[0];
                                    }
                                }
                                if (mapid >= 10324 && mapid <= 10329 || canbuy == 0)
                                {
                                    ModelProxy.change("movetips", "error", "您的今日副本次数已用完，请明日在来！");
                                    return;
                                }
                                instancereset = ModelProxy.getValue("data", "instancereset");
                                cost = useBind ? (cfg.bangyuan) : (cfg.price);
                                if (instancereset)
                                {
                                    if (instancereset[mapid] >= canbuy)
                                    {
                                        ModelProxy.change("movetips", "error", "您今日不能再次挑战该副本，请明日再来！");
                                        return;
                                    }
                                    if (!useBind)
                                    {
                                        cost = int(instancereset[mapid]) * cost + cost;
                                    }
                                    else
                                    {
                                        cost = int(instancereset[mapid]) * cost + cost;
                                    }
                                }
                                if (!useBind)
                                {
                                    Alert2.show("今日免费次数已用完，等待明天刷新，或花费 " + MColor.getHMTL(cost + "元宝", 6) + " 继续挑战该副本？优先消耗“副本挑战令”", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    PluginManager.instance.sendToServer("instance", CMDInstance.NpcInstance, {mapid:mapid, type:1});
                }
                return;
            }// end function
            );
                                }
                                else
                                {
                                    Alert2.show("今日免费次数已用完，等待明天刷新，或花费 " + MColor.getHMTL(cost + "绑元", 6) + " 继续挑战该副本？优先消耗“副本挑战令”", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    PluginManager.instance.sendToServer("instance", CMDInstance.NpcInstance, {mapid:mapid, type:2});
                }
                return;
            }// end function
            );
                                }
                                return;
                            }
                        }
                    }
                    PluginManager.instance.sendToServer("instance", CMDInstance.NpcInstance, {mapid:mapid, type:0});
                }
            }
            return;
        }// end function

    }
}
